﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;
using System.Collections.Generic;

namespace Runda.CMS.Portal.NoticeManage
{
    public partial class DutyAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SystemBll bll = new SystemBll();
                List<SysDutyGroupEntity> list = bll.GetAll<SysDutyGroupEntity>("");

                ddlDutyGroup.DataSource = list;
                ddlDutyGroup.DataTextField = "DuctyGroupName";
                ddlDutyGroup.DataValueField = "DutyGroupID";
                ddlDutyGroup.DataBind();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!txtDate.SelectedDate.HasValue)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "error1", "alert('请选择日期!');", true);
                return;
            }

            if (ddlDutyGroup.SelectedValue == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "error1", "alert('请选择值班组!');", true);
                return;            
            }

            SystemBll bll = new SystemBll();
            SysDutyEntity entity = new SysDutyEntity();
            entity.DutyGroupID = new Guid(ddlDutyGroup.SelectedValue);
            entity.Date = txtDate.SelectedDate.Value;
            entity.CreatedBy = CurrentUserEntity.UserName;
            entity.CreatedOn = DateTime.Now;

            bll.Insert(entity);
            ClientScript.RegisterStartupScript(this.GetType(), "error1", "alert('保存成功!');window.opener.document.getElementById('ctl00_cphBody_btnRefersh').click();window.close();", true);
        }
    }
}
